home *** CD-ROM | disk | FTP | other *** search
/ Computer Life 1997 February / Computer Life February 1997.iso / ADIBODEM / WING / TIMEWING.CP_ / TIMEWING.CP
Text File  |  1994-09-20  |  27KB  |  948 lines

  1. /**************************************************************************
  2.  
  3.     TIMEWING.CPP - A timing demo for WinG
  4.  
  5.  **************************************************************************/
  6. /**************************************************************************
  7.  
  8.     (C) Copyright 1994 Microsoft Corp.  All rights reserved.
  9.  
  10.     You have a royalty-free right to use, modify, reproduce and 
  11.     distribute the Sample Files (and/or any modified version) in 
  12.     any way you find useful, provided that you agree that 
  13.     Microsoft has no warranty obligations or liability for any 
  14.     Sample Application Files which are modified. 
  15.  
  16.  **************************************************************************/
  17.  
  18. #include <windows.h>
  19. #include <windowsx.h>
  20. #include <commdlg.h>
  21. #include "timewing.h"
  22.  
  23. #include <string.h>
  24. #include <mmsystem.h>
  25. #include <fstream.h>
  26. #include <strstrea.h>
  27.  
  28. #include <wing.h>
  29. #include "..\utils\utils.h" 
  30.  
  31. /*----------------------------------------------------------------------------*\
  32. |                                        |
  33. | g l o b a l   v a r i a b l e s                        |
  34. |                                        |
  35. \*----------------------------------------------------------------------------*/
  36. static  char       szAppName[]="WinG Timer Sample";
  37. static  char       szAppFilter[]="Bitmaps\0*.bmp\0";
  38.  
  39. static  HINSTANCE  hInstApp;
  40. HWND               hwndApp;
  41. static  HPALETTE   hpalApp;
  42. static  BOOL       fAppActive;
  43.  
  44. static int         dx, dy;
  45.  
  46. PDIB               pCurrentDIB;
  47. char               aDescription[200];
  48. char               aBuffer[5000];
  49. UINT               CurrentDIBUsage;
  50.  
  51. struct
  52. {
  53.   BITMAPINFOHEADER Header;
  54.   RGBQUAD aColors[256];
  55. } Info;
  56.  
  57. int Iterations = 100;
  58. int StretchMenu = 0;
  59. float StretchFactor = 1;
  60.  
  61. /*----------------------------------------------------------------------------
  62.  
  63. Timers
  64.  
  65. */
  66.  
  67. struct timing_result;
  68. typedef void timer( timing_result *pResults, HWND Window );
  69.  
  70. timer TimeStretchBlt;
  71. timer TimeStretchDIBits;
  72. timer TimeWinGBU;
  73. timer TimeWinGTD;
  74.  
  75.  
  76. /*----------------------------------------------------------------------------
  77.  
  78. Timer structure.
  79.  
  80. */
  81.  
  82. void PrintTimingResults( ostream &Out );
  83.  
  84. struct timing_result
  85. {
  86.   DWORD Time;
  87.   timer *pTimer;
  88.   char const *pDescription;
  89. } aTimings[] =
  90. {
  91.   0, TimeStretchBlt, "StretchBlt",
  92.   0, TimeStretchDIBits, "StretchDIBits",
  93.   0, TimeWinGTD, "WinGStretchBlt top-down",
  94.   0, TimeWinGBU, "WinGStretchBlt bottom-up",
  95. };
  96.  
  97. int const NumberOfTimings = sizeof(aTimings) / sizeof(aTimings[0]);
  98.   
  99.  
  100.  
  101.   
  102. #if defined(WIN32) || defined(_WIN32)
  103.   #define _export
  104. #endif
  105.  
  106. /*----------------------------------------------------------------------------*\
  107. |                                        |
  108. | f u n c t i o n   d e f i n i t i o n s                    |
  109. |                                        |
  110. \*----------------------------------------------------------------------------*/
  111.  
  112. LONG FAR PASCAL _export  AppWndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam);
  113. int   ErrMsg (LPSTR sz,...);
  114. LONG  AppCommand (HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam);
  115.  
  116. void  AppExit(void);
  117. BOOL  AppIdle(void);
  118. void  AppOpenFile(HWND hwnd, LPSTR szFileName);
  119.  
  120. /*----------------------------------------------------------------------------*\
  121. | AppAbout( hDlg, uiMessage, wParam, lParam )                  |
  122. |                                        |
  123. | Description:                                 |
  124. |   This function handles messages belonging to the "About" dialog box.    |
  125. |   The only message that it looks for is WM_COMMAND, indicating the use   |
  126. |   has pressed the "OK" button.  When this happens, it takes down       |
  127. |   the dialog box.                              |
  128. |                                        |
  129. | Arguments:                                   |
  130. |   hDlg      window handle of about dialog window           |
  131. |   uiMessage   message number                       |
  132. |   wParam      message-dependent                    |
  133. |   lParam      message-dependent                    |
  134. |                                        |
  135. | Returns:                                   |
  136. |   TRUE if message has been processed, else FALSE               |
  137. |                                        |
  138. \*----------------------------------------------------------------------------*/
  139. BOOL FAR PASCAL _export AppAbout(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
  140. {
  141.   switch (msg)
  142.   {
  143.     case WM_COMMAND:
  144.       if (LOWORD(wParam) == IDOK)
  145.       {
  146.         EndDialog(hwnd,TRUE);
  147.       }
  148.       break;
  149.  
  150.     case WM_INITDIALOG:
  151.       return TRUE;
  152.   }
  153.   return FALSE;
  154. }
  155.  
  156. /*----------------------------------------------------------------------------*\
  157. | AppInit( hInst, hPrev)                                                       |
  158. |                                                                              |
  159. | Description:                                                                 |
  160. |   This is called when the application is first loaded into                   |
  161. |   memory.  It performs all initialization that doesn't need to be done       |
  162. |   once per instance.                                                         |
  163. |                                                                              |
  164. | Arguments:                                                                   |
  165. |   hInstance   instance handle of current instance                            |
  166. |   hPrev       instance handle of previous instance                           |
  167. |                                                                              |
  168. | Returns:                                                                     |
  169. |   TRUE if successful, FALSE if not                                           |
  170. |                                                                              |
  171. \*----------------------------------------------------------------------------*/
  172. BOOL AppInit(HINSTANCE hInst,HINSTANCE hPrev,int sw,LPSTR szCmdLine)
  173. {
  174.   WNDCLASS cls;
  175.  
  176.   /* Save instance handle for DialogBoxes */
  177.   hInstApp = hInst;
  178.  
  179. // Clear the System Palette so that WinGStretchBlt runs at full speed.
  180.   ClearSystemPalette();
  181.   
  182.   if (!hPrev)
  183.   {
  184.     /*
  185.      *  Register a class for the main application window
  186.      */
  187.     cls.hCursor      = LoadCursor(NULL,IDC_ARROW);
  188.     cls.hIcon      = LoadIcon(hInst,"AppIcon");
  189.     cls.lpszMenuName   = "AppMenu";
  190.     cls.lpszClassName  = szAppName;
  191.     cls.hbrBackground  = (HBRUSH)(COLOR_WINDOW + 1);
  192.     cls.hInstance    = hInst;
  193.     cls.style      = CS_BYTEALIGNCLIENT | CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS;
  194.     cls.lpfnWndProc    = (WNDPROC)AppWndProc;
  195.     cls.cbWndExtra     = 0;
  196.     cls.cbClsExtra     = 0;
  197.  
  198.     if (!RegisterClass(&cls))
  199.       return FALSE;
  200.   }
  201.  
  202.   dx = 400;
  203.   dy = 400;
  204.  
  205.   hwndApp = CreateWindow (szAppName,    // Class name
  206.               szAppName,                // Caption
  207.               WS_OVERLAPPEDWINDOW,      // Style bits
  208.               50, 50,                   // Position
  209.               dx+20,dy+75,              // Size
  210.               (HWND)NULL,               // Parent window (no parent)
  211.               (HMENU)NULL,              // use class menu
  212.               hInst,                    // handle to window instance
  213.               (LPSTR)NULL               // no params to pass on
  214.                );
  215.   ShowWindow(hwndApp,sw);
  216.  
  217.  
  218.     HMENU Menu = GetMenu(hwndApp);
  219.     CheckMenuItem(Menu,MENU_1TO1,MF_CHECKED);
  220.  
  221.     //
  222.     // build the timing menu.
  223.     //
  224.  
  225.     HMENU hmenu = GetSubMenu(Menu, 3);
  226.     DeleteMenu(hmenu, MENU_TIME, MF_BYCOMMAND);
  227.  
  228.     for (int i=0; i<NumberOfTimings; i++)
  229.     {
  230.         AppendMenu(hmenu, 0, MENU_TIME+i, aTimings[i].pDescription);
  231.     }
  232.  
  233.     hpalApp = WinGCreateHalftonePalette();
  234.     AppOpenFile(hwndApp,"frog.bmp");
  235.  
  236.     if(!pCurrentDIB)
  237.     {
  238.       // we couldn't load froggie
  239.  
  240.       PostMessage(hwndApp,WM_COMMAND,MENU_OPEN,0);
  241.     }
  242.  
  243.   return TRUE;
  244. }
  245.  
  246.  
  247. /*----------------------------------------------------------------------------*\
  248. | AppExit